package com.swyc.osschat.Test.StreamTest.Controller.Stream;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.swyc.osschat.Test.LambdaTest.Bean.Student;
import com.swyc.osschat.Test.StreamTest.Bean.SpecialityEnum;

/**
 * @author zhaol@yunrong.cn
 * @version V2.1
 * @since 2.1.0 2019/8/9 17:28
 */
public class FilterTest {
    public static void main(String[] args) {
        List<Student> students = Student.generateData();
        //todo 获取集合里面有跳舞爱好的第一个人(过滤集合元素，获取第一个符合条件的对象)
        Student student = students.stream().filter(s->isLikeDance(s)).findFirst().orElseThrow(null);
        //todo 获取集合里面所有的成年人再根据第一个爱好分组(过滤集合元素，再根据过滤后的集合进行排序)
        Map<String,List<Student>> studentMap = students.stream().filter(s->isAdult(s)).collect(Collectors.groupingBy(Student::getFirstLove));
        System.out.println("asjdalks");
    }

    public static boolean isLikeDance(Student s){
        return s.getSpecialityEnums().contains(SpecialityEnum.DANCE);
    }
    public static boolean isAdult(Student s){
        return s.getAge()>=18;
    }
}
